class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        n = len(s)
        while s[n-1] == " " :
            n-=1
        l=0
        while n >= 1 and s[n-1] != " " :
            l+=1
            n-=1
        return l